module Keybinds where

import XMonad ( spawn, sendMessage, withFocused )
import qualified XMonad.StackSet as W

import XMonad.Actions.Minimize ( maximizeWindow, minimizeWindow, withLastMinimized )

import XMonad.Util.EZConfig (additionalKeysP)
import XMonad.Util.SpawnOnce ()
import XMonad.Util.Run (spawnPipe)

import XMonad.Hooks.ManageDocks (avoidStruts, docks, manageDocks, ToggleStruts(..))

import XMonad.Layout.NoBorders (smartBorders)
import XMonad.Layout.Minimize ()
import qualified XMonad.Layout.BoringWindows as BW
import XMonad.Layout.ResizableThreeColumns ( MirrorResize(MirrorShrink, MirrorExpand) )
import XMonad.Layout.MultiToggle ( Toggle(Toggle) )
import XMonad.Layout.MultiToggle.Instances ( StdTransformers(NOBORDERS, FULL) )
import XMonad.Layout.BoringWindows ( focusDown, focusMaster, focusUp )
import XMonad.Layout.SubLayouts ( onGroup, pullGroup, GroupMsg(UnMerge) )
import XMonad.Layout.WindowNavigation ( Direction2D(D, L, R, U) )

import Vars ( defBrowser, defTerm, myEdit, myHome, mySh, scrotBase, cmdLock )


myAddKeys = [ ("M-S-<Return>"    , spawn defTerm)
            , ("M-M1-<Return>"   , spawn myEdit)
            , ("M-C-<Return>"    , spawn $ defTerm ++ " -e ranger")
            , ("M-p"             , spawn "rofi -show drun")
            , ("C-M-<Tab>"       , spawn "rofi -show window")
            , ("M-q"             , spawn "")
            , ("C-M1-l"          , spawn cmdLock)
            -- , ("M-S-q"           , spawn $ mySh ++ "back_to_kwin.sh")
            , ("M-S-q"           , spawn $ mySh ++ "logout-old.sh")
            , ("M-b"  , sendMessage ToggleStruts)
            , ("M-x"  , spawn (mySh ++ "touchpad.sh"))
            , ("M-S-x", spawn (mySh ++ "wacom.sh"))
            -- Xmonad window manipulation keys
            -- -- SubLayouts
            , ("M-C-h", sendMessage $ pullGroup L)
            , ("M-C-l", sendMessage $ pullGroup R)
            , ("M-C-k", sendMessage $ pullGroup U)
            , ("M-C-j", sendMessage $ pullGroup D)

            -- , ("M-C-m", withFocused (sendMessage . MergeAll))
            , ("M-C-u", withFocused (sendMessage . UnMerge))

            , ("M-C-,", onGroup W.focusUp')
            , ("M-C-.", onGroup W.focusDown')
            -- -- -- Submap(what it is?)
            -- -- --
            -- , ("M-s"  , submap $ defaultSublMap conf)
            -- Moving boring Windows
            , ("M-k",       focusUp)
            , ("M-j",       focusDown)
            , ("M-S-<Tab>", focusUp)
            , ("M-<Tab>",   focusDown)
            , ("M-m",       focusMaster)
            -- Toggle fullscreen window
            , ("M-f",   sendMessage $ Toggle FULL)
            -- Toggle Borders windows
            , ("M-S-f", sendMessage $ Toggle NOBORDERS)
            -- Resizable tall and columns
            , ("M-a", sendMessage MirrorExpand)
            , ("M-z", sendMessage MirrorShrink)
            -- -- Minimize/unminimize
            , ("M-n"  , withFocused minimizeWindow)
            , ("M-S-n", withLastMinimized maximizeWindow)
            -- Func keys
            -- -- Warpd
            , ("M-S-<F6>" , spawn "kill -s USR1 $(pidof deadd-notification-center)")
            -- -- Media
            , ("M-<F10>"  , spawn "playerctl play-pause")
            , ("M-S-<F10>", spawn "playerctl -a pause")
            , ("M-C-<F10>", spawn "playerctl -a play-pause")
            , ("M-<F11>"  , spawn "playerctl previous")
            , ("M-<F12>"  , spawn "playerctl next")
            -- -- Display
            -- -- -- Brightnes
            , ("<XF86MonBrightnessUp>"  , spawn "light -A 5")
            , ("<XF86MonBrightnessDown>", spawn "light -U 5")
            -- -- Volume
            -- -- -- Fn line
            , ("<XF86AudioRaiseVolume>", spawn "pactl set-sink-volume @DEFAULT_SINK@ +5%")
            , ("<XF86AudioLowerVolume>", spawn "pactl set-sink-volume @DEFAULT_SINK@ -5%")
            , ("<XF86AudioMute>"       , spawn "pactl set-sink-mute @DEFAULT_SINK@ toggle")
            -- -- -- Alt line
            , ("M-M1-<F12>", spawn "pactl set-sink-volume @DEFAULT_SINK@ +5%")
            , ("M-M1-<F11>", spawn "pactl set-sink-volume @DEFAULT_SINK@ -5%")
            , ("M-M1-<F10>", spawn "pactl set-sink-mute @DEFAULT_SINK@ toggle")
            -- -- Apps
            -- -- -- Default line
            , ("M-<F1>", spawn defBrowser)
            , ("M-<F2>", spawn "pavucontrol")
            , ("M-<F3>", spawn "telegram-desktop")
            , ("M-<F4>", spawn "gimp")
            -- -- -- Alt line (scripts)
            , ("M-M1-<F1>", spawn $ mySh ++ "power_manager.sh")
            , ("M-M1-<F2>", spawn $ mySh ++ "monitors.sh")
            , ("M-M1-<F3>", spawn $ mySh ++ "toggle_picom.sh") -- idea: toggling using haskell
            -- -- -- Screenshot
            , ("<Print>"    , spawn scrotBase)
            , ("M-<Print>"  , spawn $ scrotBase ++ " -s")
            , ("M-C-<Print>", spawn $ scrotBase ++ " -u")
            ]

